#include <cstdlib>
#include <SFML/Graphics.hpp>
#include "Option.h"
Option m_option;
#include "general.h"
const int LARGEUR(800), HAUTEUR(600);
using namespace sf;
using namespace std;
class Cheat : private sf::Thread
{
    public:
    void demarrer(Game *jeu)
    {
        m_jeu = jeu;
        Launch();
    }

    private:
    virtual void Run()
    {
        std::string commande("");
        while(commande != "quit")
        {
            cin >> commande;
            if(commande == "rafraichir")
                m_jeu->rafraichir_equip();
        }
        cout << "Arret du programme de cheat..." << endl;
        Wait();
    }
    Game *m_jeu;
};
int main()
{
    Cheat m_cheat;
    sf::SoundBuffer m_buffermenu;
    sf::Sound m_soundmenu;
    if(!m_buffermenu.LoadFromFile("sounds/menu_principal.ogg"))
    {
        cout << "Erreur dans le chargement du son principal" << endl;
    }
    else
    {
        m_soundmenu.SetBuffer(m_buffermenu);
        m_soundmenu.SetVolume(m_option.GetVolume()/2);
        m_soundmenu.SetLoop(true);
    }
    RenderWindow app(VideoMode(LARGEUR,HAUTEUR, 32), "Strategic Wars - Created by Leo Nadeau", sf::Style::Close);
    app.SetFramerateLimit(60);
    app.UseVerticalSync(false);
    View vue(Vector2f(LARGEUR/2,HAUTEUR/2), Vector2f(LARGEUR/2,HAUTEUR/2));
    //vue.Zoom(2.f);
    Vector2f sourisAct, sourisPre,vent;
    vent.x = -5;
    vent.y = 4;
    Terrain terre;
    // Boucle principale
    vector<Unite*> unite;
    int choix(0);
    m_soundmenu.Play();
    choix = MenuPrincipal(&app, true);
    Interface_Option option_i;
    int ia=0;
    while(choix)
    {
        choix = MenuPrincipal(&app, false);
        if(choix == 2)
        {
            Game fenetreMulti("terrain/temporaire/");
            MenuMultijoueur multi;
            generationTerrain generation;
            generation.boucle(&app);
            m_cheat.demarrer(&fenetreMulti);
            unite = multi.Boucle(&app, &ia);
            for(int i(0);i<unite.size();i++)
            {
                fenetreMulti.addUnite(unite[i]);
            }
            m_soundmenu.Stop();
            fenetreMulti.boucle(&app, ia);
        }
        if(choix == 3)
            option_i.boucle(&app);
    }
    return EXIT_SUCCESS;
}
